﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>创建</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link type="text/css" href="../Layui/css/layui.css" rel="stylesheet" media="all">
    <style>
        /*.layui-form input[type=checkbox], .layui-form input[type=radio], .layui-form select {
            display: block;
        }*/
        .layui-form-checkbox[lay-skin=primary] {
            height: auto !important;
            line-height: normal !important;
            min-width: 18px;
            min-height: 18px;
            border: none !important;
            margin-right: 0;
            padding-left: 28px;
            padding-right: 0;
            background: 0 0;
        }
    </style>
</head>
<body>
    <div id="el">
        <div style=" margin-top:20px;"></div>
        <fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
            <legend>学员签到</legend>
        </fieldset>
        <div class="layui-form-item layui-form" style="margin-left:1rem">
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <div class="layui-input-inline">
                        <select name="FlowingType" lay-verify="required" lay-search="" lay-filter="FlowingType" id="_FlowingType1" class="layui-input-block ">
                            <option value="">签到状态</option>
                            <option value="3">未签到</option>
                            <option value="4">已签到</option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="layui-inline">
                <div class="layui-input-inline">
                    <input type="text" name="email" lay-verify="email" autocomplete="off" class="layui-input" placeholder="手机号" v-model="phoneNumber">
                </div>
            </div>
            <div class="layui-inline" style="width:5.5rem">
                <div class="layui-input-inline">
                    <button class="layui-btn layui-btn-normal" v-on:click="vm.openCustomers()">添加学员</button>
                </div>
            </div>
            <div class="layui-inline" style="width:4.5rem">
                <div class="layui-input-inline">
                    <button class="layui-btn layui-btn-normal" v-on:click="vm.StudentInfo()">搜索</button>
                </div>
            </div>
            <div class="layui-inline" style="min-width: 33rem;">
                <div class="layui-input-inline" style="min-width: 33rem;">
                    <template v-if="Activity">
                        <template v-if="Activity.ActType==1">
                            活动名称:{{Activity.ActivityName}},扣课时:{{Activity.Classhour?Activity.Classhour:0}}课时,会员价:{{Activity.MPrice?Activity.MPrice:0}},非会员价:{{Activity.NoMPrice?Activity.NoMPrice:0}}
                        </template>
                        <template v-if="Activity.ActType==0">
                            活动名称:{{Activity.ActivityName}}-
                            <span style="color:green">免费</span>
                        </template>
                    </template>
                </div>
            </div>
            <div class="layui-inline" style="width: 5rem;">
                <div class="layui-input-inline">
                    <button class="layui-btn layui-btn-primary layui-btn-xs" v-on:click="PsiGin(0)">批量签到</button>
                    <button class="layui-btn layui-btn-primary layui-btn-xs" v-on:click="PsiGin(1)">批量撤销签到</button>
                </div>
            </div>
        </div>
        <div class="layui-form layui-form-item">
            <table class="layui-table">
                <thead>
                    <tr>
                        <th></th>
                        <th>学员姓名</th>
                        <th>家长姓名</th>
                        <th>手机号码</th>
                        <th>会员</th>
                        <th>报名状态</th>
                        <th>备注</th>
                        <th>预约日期</th>
                        <th>扣课时</th>
                        <th>扣课/费用</th>
                        <th>报名来源</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody>
                    <template v-if="Student">
                        <tr v-for="(item,index) in Student">
                            <td>
                                <input type="checkbox" name="delbox" style="display:block;" v-bind:value="item.id">
                            </td>
                            <td>{{item.Name}}</td>
                            <td>{{item.LinkName}}</td>
                            <td>{{item.Tel}}</td>
                            <td>
                                <template v-if="item.IsMember==0">
                                    非会员
                                </template>
                                <template v-if="item.IsMember==1">
                                    会员
                                </template>
                            </td>
                            <td>
                                <template v-if="item.state==1">
                                    已确认未收费
                                </template>
                                <template v-if="item.state==2">
                                    已确认未入账
                                </template>
                                <template v-if="item.state==3">
                                    已缴费
                                </template>
                                <template v-if="item.state==4">
                                    已签到
                                </template>
                                <template v-if="item.state==5">
                                    撤销签到
                                </template>
                                <template v-if="item.state==6">
                                    已取消报名已退费
                                </template>
                            </td>
                            <td>{{item.Remark}}</td>
                            <td>{{ChangeDateFormat(item.subscribeDate)}}</td>
                            <td>{{item.DecClass}}</td>
                            <td>{{item.Decprice}}</td>
                            <td>{{item.Soure}}</td>
                            <td>
                                <template v-if="Activity.ActType==0">
                                    @*//免费*@
                                    <template v-if="item.state==3">
                                        <a class="layui-btn layui-bg-blue layui-btn-xs" v-on:click="signIn(item.id,4)">签到</a>
                                    </template>
                                    <template v-if="item.state==4&&(!is_Monthed(ChangeDateFormat(item.subscribeDate)))">
                                        <a class="layui-btn layui-bg-blue layui-btn-xs" v-on:click="signIn(item.id,5)">撤销签到</a>
                                    </template>
                                    <template v-if="item.state==5">
                                        <a class="layui-btn layui-bg-blue layui-btn-xs" v-on:click="signIn(item.id,4)">签到</a>
                                    </template>
                                </template>
                                <template v-if="Activity.ActType==1">
                                    @*//收费*@
                                    <template v-if="item.IsMember==0">
                                        @*//非会员*@
                                        <template v-if="item.state==1">
                                            <a class="layui-btn layui-bg-blue layui-btn-xs" v-on:click="AddFK(item.Decprice,item.Cid,item.guid,item.id)">缴费</a>
                                        </template>
                                        <template v-if="item.state==3">
                                            <a class="layui-btn layui-bg-blue layui-btn-xs" v-on:click="signIn(item.id,4)">签到</a>
                                            <template v-if="item.Decprice>0">
                                                <a class="layui-btn layui-bg-blue layui-btn-xs" v-on:click="AddTK(item.Decprice,item.Cid,item.guid,item.id)">退费</a>
                                            </template>
                                        </template>
                                        <template v-if="item.state==4&&(!is_Monthed(ChangeDateFormat(item.subscribeDate)))">
                                            <a class="layui-btn layui-bg-blue layui-btn-xs" v-on:click="signIn(item.id,5)">撤销签到</a>
                                        </template>
                                        <template v-if="item.state==5">
                                            <a class="layui-btn layui-bg-blue layui-btn-xs" v-on:click="signIn(item.id,4)">签到</a>
                                        </template>
                                    </template>
                                    <template v-if="item.IsMember==1">
                                        @*//会员*@
                                        <template v-if="item.Decprice>0">
                                            <template v-if="item.state==1">
                                                <a class="layui-btn layui-bg-blue layui-btn-xs" v-on:click="AddFK(item.Decprice,item.Cid,item.guid,item.id)">缴费</a>
                                            </template>
                                            <template v-if="item.state==3">
                                                <a class="layui-btn layui-bg-blue layui-btn-xs" v-on:click="signIn(item.id,4)">签到</a>
                                                <template v-if="item.Decprice>0">
                                                    <a class="layui-btn layui-bg-blue layui-btn-xs" v-on:click="AddTK(item.Decprice,item.Cid,item.guid,item.id)">退费</a>
                                                </template>
                                            </template>
                                            <template v-if="item.state==4&&(!is_Monthed(ChangeDateFormat(item.subscribeDate)))">
                                                <a class="layui-btn layui-bg-blue layui-btn-xs" v-on:click="signIn(item.id,5)">撤销签到</a>
                                            </template>
                                            <template v-if="item.state==5">
                                                <a class="layui-btn layui-bg-blue layui-btn-xs" v-on:click="signIn(item.id,4)">签到</a>
                                            </template>
                                        </template>
                                        <template v-else>
                                            <template v-if="item.state==3">
                                                <a class="layui-btn layui-bg-blue layui-btn-xs" v-on:click="signIn(item.id,4)">签到</a>
                                            </template>
                                            <template v-if="item.state==4&&(!is_Monthed(ChangeDateFormat(item.subscribeDate)))">
                                                <a class="layui-btn layui-bg-blue layui-btn-xs" v-on:click="signIn(item.id,5)">撤销签到</a>
                                            </template>
                                            <template v-if="item.state==5">
                                                <a class="layui-btn layui-bg-blue layui-btn-xs" v-on:click="signIn(item.id,4)">签到</a>
                                            </template>
                                        </template>
                                    </template>
                                </template>
                            </td>
                        </tr>
                    </template>
                </tbody>
            </table>
        </div>
    </div>
    <!--模仿bootstrap的模态框-->
    <div id="Customers" style="display: none;">
        <!--可再建编辑表单-->
        <div id="kh">
            <div class="layui-form-item" style="margin-top:1rem">
                <div class="layui-col-md8">
                    <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入手机号" class="layui-input" style="margin-left:5rem" v-model="Tel">
                </div>
                <div class="layui-col-md2">
                    <button class="layui-btn" style="margin-left:6rem" onclick="vmKH.khInfo()">搜索</button>
                </div>
            </div>
            <div class="layui-form" align="center">
                <table class="layui-table" style="width: 95%;">
                    <thead>
                        <tr>
                            <th>学员姓名</th>
                            <th>联系方式</th>
                            <th>联系人姓名</th>
                            <th>联系人关系</th>
                            <th>是否报名</th>
                            <th>是否会员</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        <template v-if="khList">
                            <tr v-for="(item,index) in khList">
                                <td>{{item.CustName}}</td>
                                <td>{{item.CustTel}}</td>
                                <td>{{item.LinkName}}</td>
                                <td>{{item.LinkRelation}}</td>
                                <td>
                                    <template v-if="item.isBM==0">
                                        未报名
                                    </template>
                                    <template v-else-if="item.isBM==1">
                                        已报名
                                    </template>
                                </td>
                                <td>
                                    <template v-if="item.isHY==0">
                                        非会员
                                    </template>
                                    <template v-else-if="item.isHY==1">
                                        会员
                                    </template>
                                </td>
                                <td>
                                    <div class="layui-btn-group" v-if="item.isBM==0">
                                        <button class="layui-btn layui-btn-primary layui-btn-xs" v-on:click="ActivityBM(item.id,item.CustName,item.CustTel,item.LinkName,item.isHY,item.CustFrom)">选择</button>
                                    </div>
                                    <div class="layui-btn-group" v-if="item.isBM==1">
                                        <button class="layui-btn layui-btn-primary layui-btn-xs" v-on:click="CancelBM(item.id)">取消报名</button>
                                    </div>
                                </td>
                            </tr>
                        </template>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <script type="text/javascript" src="../Htc/jquery-1.11.2.min.js"></script>
    <script type="text/javascript" src="../Htc/vue.min.js"></script>
    <script type="text/javascript" src="../Layui/layui.js"></script>
    <script>
        layui.config({
            base: '../Layui/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use('index');
        //Demo
        layui.use(['form', 'layer', 'laydate', 'element'], function () {
            var laydate = layui.laydate;
            var form = layui.form;
            var element = layui.element;
            layer = layui.layer
            //监听提交
            form.on('submit(formDemo)', function (data) {
                layer.msg(JSON.stringify(data.field));
                return false;
            });
            //监听下拉菜单
            form.on('select(FlowingType)', function (data) {
                //layer.msg(JSON.stringify(data.value));
                vm.siginState = data.value;
                vm.StudentInfo(data.value);
                return false;
            });

            //执行一个laydate实例
            laydate.render({
                elem: '#BirdDate' //指定元素
            });
        });

    </script>
    <script>
        function HideModal(id) {
            layui.layer.closeAll();
        }
        var vm = new Vue({
            el: '#el',
            data: {
                siginState: '',
                phoneNumber: '',
                Student: [],
                Activity:[]
            },
            created: function () {
                this.ActivityInfo();
                this.StudentInfo()
            },
            methods: {
                is_Monthed: function (date) {
                    var date = new Date;
                    var d2 = new Date(date);
                    var signInMonth = d2.getMonth()+1;
                    console.log(d2.getMonth());
                    var NowMonth = date.getMonth() + 1;
                    if (NowMonth == 1 && signInMonth==12) {
                        return true;
                    }
                    if (NowMonth > signInMonth) {
                        return true;
                    }
                    return false
                },
                PsiGin: function (type) {//0签到1取消签到
                    if (type == 0) {
                        if (vm.siginState != 3) {//4已签到3未签到
                            layer.msg("请先进行未签到搜索！");
                            var obj = document.getElementsByName("delbox");
                            for (k in obj) {
                                obj[k].checked = false;
                            }
                            return;
                        }
                    }
                    else if (type == 1) {
                        if (vm.siginState != 4) {//4已签到3未签到
                            layer.msg("请先进行已签到搜索！");
                            var obj = document.getElementsByName("delbox");
                            for (k in obj) {
                                obj[k].checked = false;
                            }
                            return;
                        }
                    }

                    var obj = document.getElementsByName("delbox");
                    var data = [];
                    var checkNum = 0;
                    for (k in obj) {
                        if (obj[k].checked) {
                            //alert(obj[k].value)
                            data.push(obj[k].value);
                            checkNum++;
                        }
                    }
                    if (checkNum == 0) {
                        layer.msg("最少选择一项！");
                        return;
                    }
                    var act = "1=1";
                    if (type != null) {
                        act += "&type=" + type;
                    }
                    if (data.length > 0) {
                        act += "&Upid=" + JSON.stringify(data);
                    }
                    $.ajax({
                        data: '',
                        url: "../Activitys/ActivitySp/UpSigin?" + act+"&id=" +@ViewBag.id+'&keyCode=@ViewBag.KeyCode',
                        type: "post",
                        dataType: "json",
                        success: function (data) {
                            if (data.code == "0000") {
                                layer.msg("操作成功！");
                                vm.StudentInfo();
                            }
                            else if (data.code == "0009") {
                                layer.msg("参数为空！");
                            }
                            else if (data.code == "0001") {
                                layer.msg("您没有权限！");
                            }
                            else {
                                layer.msg("数据为空！");
                            }
                        }
                    })

                },
                AddTK:function (je,cid,guid,aid)
                     {
                 layer.open({
                        type: 2,
                     content: '../Account/At?id=-1&cid=' + cid + '&FlowingType=00203001&guid=' + guid + '&ActivityId=' + aid +'&keyCode=@ViewBag.KeyCode',
                        title: '添加退款内容',
                        area: ['650px','650px'],
                        maxmin: false,
                     success: function (layero, index) {
                  var body = layer.getChildFrame('body', index);
                  body.find('#_Account').val(je);
                  },
                     end: function (index, layero) {
                         vm.StudentInfo();
                    }
                   });
                  },
                   AddFK:function (je,cid,guid,aid)
                     {
                 layer.open({
                        type: 2,
                     content: '../Account/At?id=-1&cid=' + cid + '&FlowingType=00103001&guid=' + guid + '&ActivityId=' + aid +'&keyCode=@ViewBag.KeyCode',
                        title: '添加付款内容',
                        area: ['650px','650px'],
                        maxmin: false,
                     success: function (layero, index) {
                  var body = layer.getChildFrame('body', index);
                  body.find('#_Account').val(je);
            },
                     end: function (index, layero) {
                         vm.StudentInfo();

                    }
                   });
             },
                ChangeDateFormat: function (val) {
                    if (val != null) {
                        var date = new Date(parseInt(val.replace("/Date(", "").replace(")/", ""), 10));
                        //月份为0-11，所以+1，月份小于10时补个0
                        var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
                        var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
                        return date.getFullYear() + "-" + month + "-" + currentDate;
                    }
                    return "";
                },
                signIn: function (id, type) {//签到4，取消签到5
                    var act = "1=1";
                    if (id) {
                        act += "&id=" + id;
                    }
                    if (type) {
                        act += "&type=" + type;
                    }
                    $.ajax({
                        data: '',
                        url: "../Activitys/ActivitySp/signIn?" + act+"&vid=" +@ViewBag.id+'&keyCode=@ViewBag.KeyCode',
                        type: "post",
                        dataType: "json",
                        success: function (data) {
                            if (data.code == "0000") {
                                layer.msg("操作成功！");
                                vm.StudentInfo();
                            }
                            else if (data.code == "0009") {
                                layer.msg("参数为空！");
                            }
                            else if (data.code == "0001") {
                                layer.msg("您没有权限！");
                            }
                            else {
                                layer.msg("数据为空！");
                            }
                        }
                    })

                },
                openCustomers: function () {
                    var act = "";
                    if (vm.phoneNumber) {
                        act += "&Tel=" + vm.phoneNumber;
                        $.ajax({
                            data: '',
                            url: "../Activitys/ActivitySp/KHInfo?Aid=" + @ViewBag.id+ act+"&id=" +@ViewBag.id+'&keyCode=@ViewBag.KeyCode',
                            type: "post",
                            dataType: "json",
                            success: function (data) {
                                if (data.code == "0000") {
                                    if (data.data.length >= 1) {
                                        vmKH.ActivityBM(data.data[0].id, data.data[0].CustName, data.data[0].CustTel, data.data[0].LinkName, data.data[0].isHY, data.data[0].CustFrom);
                                    } else {
                                        layui.use(['layer'], function () {
                                            var layer = layui.layer, $ = layui.$;
                                            layer.open({
                                                type: 1,//类型
                                                area: ['50.14rem', '40.14rem'],//定义宽和高
                                                title: '选择学员',//题目
                                                shadeClose: false,//点击遮罩层关闭
                                                content: $('#Customers')//打开的内容
                                            });
                                        })
                                        vmKH.khInfo(vm.phoneNumber);
                                    }
                                }
                                else if (data.code == "0009") {
                                    layer.msg("参数为空！");
                                }
                                else if (data.code == "0001") {
                                    layer.msg("您没有权限！");
                                }
                                else {
                                    layer.msg("数据为空！");
                                }
                            }
                        })
                    }
                    else {

                        layui.use(['layer'], function () {
                            var layer = layui.layer, $ = layui.$;
                            layer.open({
                                type: 1,//类型
                                area: ['50.14rem', '40.14rem'],//定义宽和高
                                title: '选择学员',//题目
                                shadeClose: false,//点击遮罩层关闭
                                content: $('#Customers')//打开的内容
                            });
                        })
                    }




                },
                ActivityInfo: function () {
                     $.ajax({
                        data:'',
                         url: "../Activitys/ActivitySp/ActivityInfo?id=" +@ViewBag.id+'&keyCode=@ViewBag.KeyCode',
                        type: "post",
                         dataType: "json",
                        success: function (data) {
                            if (data.code == "0000") {
                                vm.Activity= data.data[0];
                            }
                            else if (data.code == "0009") {
                                layer.msg("参数为空！");
                            }
                            else if (data.code == "0001") {
                                layer.msg("您没有权限！");
                            }
                            else {
                                layer.msg("数据为空！");
                            }
                        }
                    })
                },
                StudentInfo: function (siginState) {
                    var act = "1=1";
                    if (@ViewBag.id) {
                        act +="&Aid="+@ViewBag.id;
                    }
                    if (siginState) {
                        act += "&siginState=" + siginState;
                    }
                    else if (this.siginState) {
                        act += "&siginState=" + this.siginState;
                    }
                    if (this.phoneNumber) {
                        act += "&phoneNumber=" + this.phoneNumber;
                    }
                     $.ajax({
                        data:'',
                         url: "../Activitys/ActivitySp/StudentInfo?" +act+"&id=" +@ViewBag.id+'&keyCode=@ViewBag.KeyCode',
                        type: "post",
                         dataType: "json",
                        success: function (data) {
                            if (data.code == "0000") {
                                vm.Student = data.data;
                            }
                            else if (data.code == "0009") {
                                layer.msg("参数为空！");
                            } else if (data.code == "0001") {
                                layer.msg("您没有权限！");
                            }
                            else {
                                layer.msg("数据为空！");
                            }
                        }
                    })
                }
            }
        })
        var vmKH = new Vue({
            el: '#kh',
            data: {
                Tel:'',
                khList:[]
            },
            created: function () {
                this.khInfo();
            },
            methods: {
                khInfo: function (phone) {
                    var act = "&1=1";
                    if (phone) {
                        act += "&Tel=" + phone;
                    }
                    else {
                        act += "&Tel=" + this.Tel;
                    }
                     $.ajax({
                         data: '',
                         url: "../Activitys/ActivitySp/KHInfo?Aid=" + @ViewBag.id+ act+"&id=" +@ViewBag.id+'&keyCode=@ViewBag.KeyCode',
                        type: "post",
                         dataType: "json",
                        success: function (data) {
                            if (data.code == "0000") {
                                vmKH.khList = data.data;
                                datalist = data.data;
                            }
                            else if (data.code == "0009") {
                                layer.msg("参数为空！");
                            }
                            else if (data.code == "0001") {
                                layer.msg("您没有权限！");
                            }
                            else {
                                layer.msg("数据为空！");
                            }
                        }
                    })
                },
                ActivityBM: function (Cid, Name, Tel, LinkName, IsMember, Soure) {
                       var data = {
                           Cid:Cid,//客户id,非会员客户id为空
                           ActivityId: vm.Activity.id,//活动ID
                           Name: Name,//学员名称
                           Tel: Tel,//联系电话
                           LinkName: LinkName,//家长姓名
                           IsMember: IsMember,//是否会员0非会员，1会员
                           DecClass: vm.Activity.Classhour,//扣课时
                           Decprice: IsMember == 0 ? vm.Activity.NoMPrice : vm.Activity.MPrice,//扣费用
                           Soure: Soure,//报名来源
                           state: 0,//免费状态3，收费非会员1会员扣费金额>0为1否则3
                           //vm.Activity.ActType == 0 ? 3 : (vm.Activity.ActType == 1 && IsMember == 0) ? 1 : (IsMember == 0 && Decprice > 0) ? 1 : 3
                           @*//guid:'@ViewBag.guid',*@
                    }

                    if (vm.Activity.ActType == 0) {//免费
                        data.state = 3;
                    }
                    else if (vm.Activity.ActType == 1) {//收费
                        if (IsMember == 0) {
                            data.state = 1;
                        }
                        else if (IsMember == 1) {
                            if (data.Decprice > 0) {
                                data.state = 1;
                            }
                            else {
                                data.state = 3;
                            }
                        }

                    }
                    $.ajax({
                        data: '',
                        url: "../Activitys/ActivitySp/ActivityBM?v=" + JSON.stringify(data)+"&id=" +@ViewBag.id+'&keyCode=@ViewBag.KeyCode',
                        type: "post",
                        dataType: "json",
                        success: function (data) {
                            if (data.code == "0000") {
                                layer.msg("先择成功！");
                                vmKH.khInfo();
                                vm.StudentInfo();
                            }
                            else if (data.code == "0009") {
                                layer.msg("已报名！");
                            }
                            else if (data.code == "0001") {
                                layer.msg("您没有权限！");
                            }
                            else {
                                layer.msg("选择失败！");
                            }
                        }
                    })

                },
                CancelBM: function (Cid) {//取消报名
                    $.ajax({
                        data: '',
                        url: "../Activitys/ActivitySp/CancelBM?Cid=" + Cid+"&id=" +@ViewBag.id+'&keyCode=@ViewBag.KeyCode',
                        type: "post",
                        dataType: "json",
                        success: function (data) {
                            if (data.code == "0000") {
                                layer.msg("操作成功！");
                                vmKH.khInfo();
                                vm.StudentInfo();
                            }
                            else if (data.code == "0009") {
                                layer.msg("参数为空！");
                            }
                            else if (data.code == "0001") {
                                layer.msg("您没有权限！");
                            }
                            else {
                                layer.msg("操作失败！");
                            }
                        }
                    })

                }
            }
        })
    </script>
</body>
</html>